<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./vue.js"></script>
    <style>
        h2,
        p {
            margin: 0;
        }

        .box {
            margin: 30px auto;
            width: 300px;
        }

        #user,
        #message {
            box-sizing: border-box;
            width: 300px;
            border: 1px solid #000;
            padding: 10px;
            height: 100px;
            resize: none;
            display: block;
        }

        #user {
            padding: 0 10px;
            height: 30px;
            margin-bottom: 10px;
        }

        #btn {
            display: block;
            margin: 10px auto;
            width: 60%;
            height: 40px;
        }

        #list {
            border-top: 1px solid #000;
            padding: 10px 0 0;
            margin: 0;
            list-style: none;
        }

        #list li {
            position: relative;
            font: 14px/30px "宋体";
            border-bottom: 1px solid #000;
            padding: 0 15px;
            overflow: hidden;
        }

        .clos {
            position: absolute;
            right: 5px;
            top: 10px;
        }

        .clos2 {
            position: absolute;
            right: 5px;
            top: 30px;
        }

        /* .replay{
    position:absolute;
    right: 5px;
    top: 35px;
} */
        .mask {
            width: 100vw;
            height: 100vh;
            background: black;
            opacity: .3;
            position: absolute;
            left: 0;
            top: 0;
            display: none;
        }

        .comfirm {
            width: 200px;
            height: 120px;
            background: white;
            text-align: center;
            position: absolute;
            left: 50%;
            top: 30%;
            border-radius: 5px;
            transform: translate(-50%, -50%);
            overflow: hidden;
            display: none;

        }

        .comfirm button {
            /* position: absolute; */
            /* right: 10px; */
            float: right;
            margin-top: 20px;
            margin-right: 10px;
        }

        .replay {
            display: none;
        }

        .replay1 {
            display: block;
        }
    </style>
</head>

<body>
    <div class="box">
        <input type="text" id="user" v-model.trim="input.name" />
        <textarea id="message" v-model.trim="input.content">我就是传说中的无敌小明</textarea>
        <button id="btn" @click="sub">提交留言</button>
        <ul id="list">

            <li style="height: auto" v-for="(item,key) in arr">
                <h2 class="user">{{item.name}}说:</h2>
                <p>{{item.content}}</p>

                <p v-for="item in arr1">{{item.answer}}</p>

                <div :class="flag?'replay1':'replay'">
                    <input type="text" v-model="ans.answer" /><button @click="ok">确定</button>
                </div>

                <a href="javascript:;" class="clos" @click="dele(key)">删除</a>
                <a href="javascript:;" class="clos2" @click="talk(key)" key="key">回复</a>

            </li>
            <!-- <li style="height: auto">
            <h2 class="user">老师说:</h2>
            <p>小明滚出去</p>
            <p>回复的内容</p>
            <a href="javascript:;" class="clos">删除</a>
        </li> -->
        </ul>
    </div>
    <script>
        // var arr = [
        //     {
        //         name:"小张",
        //         message:"1111",
        //         replayData:[
        //             "第一条回复内容",
        //             "第二条回复内容"
        //         ]
        //     },
        //     {
        //         name:"小张",
        //         message:"1111",
        //         replayData:[
        //             "第一条回复内容",
        //             "第二条回复内容"
        //         ]
        //     },
        //     {
        //         name:"小张",
        //         message:"1111",
        //         replayData:[
        //             "第一条回复内容",
        //             "第二条回复内容"
        //         ]
        //     }
        // ]


        // 获取先关元素


        let vm = new Vue({
            data: {

                flag: false,

                input: {
                    name: "",
                    content: "",
                },
                arr: [],


                // 这个数组是将回复的内容循环渲染到p标签上
                arr1: [],
                ans: {
                    answer: ""
                },
            },
            methods: {
                // 提交留言按钮点击事件函数
                sub() {
                    let obj = {
                        name: this.input.name,
                        content: this.input.content,
                    }
                    this.arr.push(obj);
                    // this.arr.push(this.input);
                },
                // 删除事件函数
                dele(key) {
                    console.log(key);
                    this.arr.splice(key, 1);
                },
                // 回复框显隐函数
                talk(key) {
                    console.log(key);
                    this.flag = !this.flag;
                },

                // 回复确定按钮点击事件
                ok() {
                    // 创建一个新对象，让和v-model和相关联的对象里的值断开关系，并将这个新对象push进数组里去循环渲染，就不会产生一写新内容，之前的内容就跟着变的情况了
                    let ans1={
                        answer:this.ans.answer,
                    };
                    this.arr1.push(ans1);
                    // this.arr1.push(this.ans);
                    console.log(this.arr1);


                }
            }
        }).$mount(".box");
    </script>
</body>

</html>